﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using QuanLyDuocPham.Controllers.QuanLyHeThong.DanhMuc;
using QuanLyDuocPham.Controllers.QuanLyHeThong.NhapXuat;

namespace QuanLyDuocPham.Controllers.UC.QuanLyHeThong.NhapXuat
{
    /// <summary>
    /// Interaction logic for UC_DDHXUAT_CT_View.xaml
    /// </summary>
    public partial class UC_DDHXUAT_CT_View : UserControl
    {
        public UC_DDHXUAT_CT_View()
        {
            InitializeComponent();
        }
        public delegate void added();
        public added done;

        string ma_xuat;


        public string _ma_xuat
        {
            set
            {
                ma_xuat = value;
            }
        }

        string ma_kho;
        public string _ma_kho
        {
            set
            {
                ma_kho = value;
            }
        }
        Boolean is_edit;


        public Boolean _is_edit
        {
            set
            {
                is_edit = value;
            }
        }
        DUOCPHAM_Control dpctrl = new DUOCPHAM_Control();
        GIA_Control giactrl = new GIA_Control();
        DDH_XUAT_CT_Control xctctrl = new DDH_XUAT_CT_Control();
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            btnNHAPCT_Save.IsEnabled = false;
            dpctrl.loadComboBox(cmbListDP);
            if (is_edit == true)
            {
                xctctrl.loadDataTemp2_Edit(ma_xuat, lvNHAPCT_List);
            }
        }

        private void btnNHAPCT_Add_Click(object sender, RoutedEventArgs e)
        {
            xctctrl.XuLyBangTam("add", lvNHAPCT_List, ma_xuat, cmbListDP, txtTL_HoaHong, txtSoLuong, txtGia_Ban, txtChiet_Khau, txtGhi_Chu);
            xctctrl.addandloadDataTemp2();
            clearNHAPCT();
        }
        private void clearNHAPCT()
        {
            cmbListDP.SelectedItem = null;
            txtTL_HoaHong.Clear();
            
            txtSoLuong.Clear();
            txtGia_Ban.Clear();
            txtChiet_Khau.Clear();
            txtGhi_Chu.Document.Blocks.Clear();

        }

        private void cmbListDP_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            txtGia_Ban.Text = giactrl.loadGiaSiDP(cmbListDP);

        }

        private void btnNHAPCT_Delete_Click(object sender, RoutedEventArgs e)
        {
            xctctrl.XuLyBangTam("delete", lvNHAPCT_List, ma_xuat, cmbListDP, txtTL_HoaHong, txtSoLuong, txtGia_Ban, txtChiet_Khau, txtGhi_Chu);
            xctctrl.addandloadDataTemp2();
        }

        private void btnNHAPCT_Save_Click(object sender, RoutedEventArgs e)
        {
            xctctrl.XuLyBangTam("update", lvNHAPCT_List, ma_xuat, cmbListDP, txtTL_HoaHong, txtSoLuong, txtGia_Ban, txtChiet_Khau, txtGhi_Chu);
            xctctrl.addandloadDataTemp2();

            btnNHAPCT_Save.IsEnabled = false;
            btnNHAPCT_Add.IsEnabled = true;
            clearNHAPCT();
            lvNHAPCT_List.SelectedItem = null;
        }

        private void btnClear_NHAPCT_Click(object sender, RoutedEventArgs e)
        {
            clearNHAPCT();

        }

        private void lvNHAPCT_List_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            btnNHAPCT_Save.IsEnabled = true;
            btnNHAPCT_Add.IsEnabled = false;
            xctctrl.TamToView(lvNHAPCT_List, cmbListDP, txtTL_HoaHong, txtSoLuong, txtGia_Ban, txtChiet_Khau, txtGhi_Chu);
        }

        private void btnSaveAll_Click(object sender, RoutedEventArgs e)
        {
            xctctrl.deleteAllXUATCT(ma_xuat, ma_kho);
            xctctrl.TamToXUATCT();
        }

        private void btnUndo_Click(object sender, RoutedEventArgs e)
        {
            xctctrl.DDHXUAT_CTToTam(ma_xuat);

        }



    }
}
